﻿$('.main').outerHeight($(window).outerHeight() - $('header').outerHeight() - $('footer').outerHeight());



var uid = sessionStorage.getItem('uid');
if (uid == undefined || uid == 'undefined' || uid == null) {
    uid = '';
    $('#a_hq').attr('href', 'index.html');
} else {
    $('#a_hq').attr('href', 'index.html?uid=' + uid);
}


var histor = "http://hej.shqlkj.com/json/histor.ashx";
var symbol = "http://hej.shqlkj.com/json/symbol.ashx";
var quotes = 'http://hej.shqlkj.com/json/quotes.ashx';

//数据更新的频率，1000=1秒，过小会造成频繁请求，手机端会很耗流量
var sxtime = 10000;

//登录页
var loginHmtl = 'http://hej1.shqlkj.com/index/login';

//默认自选列表
var defaultZxList = [
    {
        "codeType": '5c00',
        "SYMBOL_CODE": "XAG",
        "SYMBOL_NAME": "天通白银",
        "old_name": "现货白银",
        "EXCH_CODE": "WGJS",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 12
    },
    {
        "codeType": '5a00',
        "SYMBOL_CODE": "CU",
        "SYMBOL_NAME": "[T]现货铜",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 365
    },
    {
        "codeType": '5b00',
        "SYMBOL_CODE": "AG15",
        "SYMBOL_NAME": "粤贵银",
        "old_name": "现货白银9995",
        "EXCH_CODE": "PMEC",
        "PRICE_SCALE": 1,
        "DISPLAY_ORDER": 231
    },
    {
        "codeType": "1100",
        "SYMBOL_CODE": "1A0001",
        "SYMBOL_NAME": "上证指数",
        "EXCH_CODE": "GJZS",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 15
    },
    {
        "codeType": "1100",
        "SYMBOL_CODE": "2A01",
        "SYMBOL_NAME": "深证成指",
        "EXCH_CODE": "GJZS",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 16
    }
];

var list = {
    '天交所': [{
        "codeType": '5a00',
        "SYMBOL_CODE": "XAGUSD",
        "SYMBOL_NAME": "[T]现货白银",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 1,
        "DISPLAY_ORDER": 41
    },
    {
        "codeType": '5a00',
        "SYMBOL_CODE": "PD",
        "SYMBOL_NAME": "[T]现货钯金",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 42
    },
    {
        "codeType": '5a00',
        "SYMBOL_CODE": "PT",
        "SYMBOL_NAME": "[T]现货铂金",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 43
    },
    {
        "codeType": '5a00',
        "SYMBOL_CODE": "AG1000",
        "SYMBOL_NAME": "[T]现货白银1000",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 44
    },
    {
        "codeType": '5a00',
        "SYMBOL_CODE": "PD100",
        "SYMBOL_NAME": "[T]现货钯金100",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 45
    },
    {
        "codeType": '5a00',
        "SYMBOL_CODE": "PT100",
        "SYMBOL_NAME": "[T]现货铂金100",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 46
    },
    {
        "codeType": '5a00',
        "SYMBOL_CODE": "NI",
        "SYMBOL_NAME": "[T]现货镍",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 47
    },
    {
        "codeType": '5a00',
        "SYMBOL_CODE": "NI100",
        "SYMBOL_NAME": "[T]现货镍100",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 48
    },
    {
        "codeType": '5a00',
        "SYMBOL_CODE": "CU1T",
        "SYMBOL_NAME": "[T]现货铜1T",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 121
    },
    {
        "codeType": '5a00',
        "SYMBOL_CODE": "AL1T",
        "SYMBOL_NAME": "[T]现货铝1T",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 362
    },
    {
        "SYMBOL_CODE": "AL",
        "SYMBOL_NAME": "[T]现货铝",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 363
    },
    {
        "codeType": '5a00',
        "SYMBOL_CODE": "CU",
        "SYMBOL_NAME": "[T]现货铜",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 365
    },
    {
        "codeType": '5a00',
        "SYMBOL_CODE": "AG30KG",
        "SYMBOL_NAME": "[T]现货白银30KG",
        "EXCH_CODE": "TJPME",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 369
    }],
    '广贵所': [{
        "codeType": '5b00',
        "SYMBOL_CODE": "PTXA",
        "SYMBOL_NAME": "现货铂金9995",
        "EXCH_CODE": "PMEC",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 228
    },
    {
        "codeType": '5b00',
        "SYMBOL_CODE": "PDXA",
        "SYMBOL_NAME": "现货钯金9995",
        "EXCH_CODE": "PMEC",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 229
    },
    {
        "codeType": '5b00',
        "SYMBOL_CODE": "AG100",
        "SYMBOL_NAME": "现货白银100G",
        "EXCH_CODE": "PMEC",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 230
    },
    {
        "codeType": '5b00',
        "SYMBOL_CODE": "AG15",
        "SYMBOL_NAME": "粤贵银",
        "old_name": "现货白银9995",
        "EXCH_CODE": "PMEC",
        "PRICE_SCALE": 1,
        "DISPLAY_ORDER": 231
    },
    {
        "codeType": '5b00',
        "SYMBOL_CODE": "AG1",
        "SYMBOL_NAME": "现货白银9999",
        "EXCH_CODE": "PMEC",
        "PRICE_SCALE": 1,
        "DISPLAY_ORDER": 232
    }],
    '国际外汇': [{
        "codeType": '8100',
        "SYMBOL_CODE": "USD",
        "SYMBOL_NAME": "美元指数",
        "EXCH_CODE": "WH",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 1
    },
    {
        "codeType": '8100',
        "SYMBOL_CODE": "EURUSD",
        "SYMBOL_NAME": "欧元美元",
        "EXCH_CODE": "WH",
        "PRICE_SCALE": 10000,
        "DISPLAY_ORDER": 2
    },
    {
        "codeType": '8100',
        "SYMBOL_CODE": "GBPUSD",
        "SYMBOL_NAME": "英镑美元",
        "EXCH_CODE": "WH",
        "PRICE_SCALE": 10000,
        "DISPLAY_ORDER": 3
    },
    {
        "codeType": '8100',
        "SYMBOL_CODE": "USDJPY",
        "SYMBOL_NAME": "美元日元",
        "EXCH_CODE": "WH",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 4
    },
    {
        "codeType": '8100',
        "SYMBOL_CODE": "AUDUSD",
        "SYMBOL_NAME": "澳元美元",
        "EXCH_CODE": "WH",
        "PRICE_SCALE": 10000,
        "DISPLAY_ORDER": 5
    },
    {
        "codeType": '8100',
        "SYMBOL_CODE": "USDCHF",
        "SYMBOL_NAME": "美元瑞士",
        "EXCH_CODE": "WH",
        "PRICE_SCALE": 10000,
        "DISPLAY_ORDER": 6
    },
    {
        "codeType": '8100',
        "SYMBOL_CODE": "USDCAD",
        "SYMBOL_NAME": "美元加元",
        "EXCH_CODE": "WH",
        "PRICE_SCALE": 10000,
        "DISPLAY_ORDER": 7
    }],
    '全球现货': [{
        "codeType": '5c00',
        "SYMBOL_CODE": "XAU",
        "SYMBOL_NAME": "现货黄金",
        "EXCH_CODE": "WGJS",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 10
    },
    {
        "codeType": '5c00',
        "SYMBOL_CODE": "XPD",
        "SYMBOL_NAME": "现货钯金",
        "EXCH_CODE": "WGJS",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 11
    },

    {
        "codeType": '5c00',
        "SYMBOL_CODE": "XAP",
        "SYMBOL_NAME": "现货铂金",
        "EXCH_CODE": "WGJS",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 13
    },
    {
        "codeType": '5c00',
        "SYMBOL_CODE": "XAG",
        "SYMBOL_NAME": "天通白银",
        "old_name":"现货白银",
        "EXCH_CODE": "WGJS",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 12
    },
    {
        "codeType": '5400',
        "SYMBOL_CODE": "CONC",
        "SYMBOL_NAME": "现货原油",
        "EXCH_CODE": "NYMEX",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 12
    }],
    '全球指数': [{
        "codeType": "1100",
        "SYMBOL_CODE": "1A0001",
        "SYMBOL_NAME": "上证指数",
        "EXCH_CODE": "GJZS",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 15
    },
    {
        "codeType": "1100",
        "SYMBOL_CODE": "2A01",
        "SYMBOL_NAME": "深证成指",
        "EXCH_CODE": "GJZS",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 16
    },
    {
        "codeType": "1100",
        "SYMBOL_CODE": "NASDAQ",
        "SYMBOL_NAME": "纳斯达克指数",
        "EXCH_CODE": "GJZS",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 27
    },
    {
        "codeType": "1100",
        "SYMBOL_CODE": "DJIA",
        "SYMBOL_NAME": "道琼工业",
        "EXCH_CODE": "GJZS",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 28
    },
    {
        "codeType": "1100",
        "SYMBOL_CODE": "SP500",
        "SYMBOL_NAME": "标普500",
        "EXCH_CODE": "GJZS",
        "PRICE_SCALE": 100,
        "DISPLAY_ORDER": 29
    }]
};

var codeTypeJson = [{
    "CODE_TYPE": "1100",
    "TRADE_SESSION": "0930-1130,1300-1500"
},
{
    "CODE_TYPE": "1200",
    "TRADE_SESSION": "0930-1130,1300-1500"
},
{
    "CODE_TYPE": "4200",
    "TRADE_SESSION": "0900-1015,1030-1130,1330-1500,2100-0230"
},
{
    "CODE_TYPE": "5110",
    "TRADE_SESSION": "0700-1400"
},
{
    "CODE_TYPE": "5120",
    "TRADE_SESSION": "1500-0030"
},
{
    "CODE_TYPE": "5130",
    "TRADE_SESSION": "2130-0500"
},
{
    "CODE_TYPE": "5140",
    "TRADE_SESSION": "1100-1330,1530-1730"
},
{
    "CODE_TYPE": "5150",
    "TRADE_SESSION": "1030-1300,1430-1700"
},
{
    "CODE_TYPE": "5160",
    "TRADE_SESSION": "0800-1400"
},
{
    "CODE_TYPE": "5170",
    "TRADE_SESSION": "0900-1230,1400-1700"
},
{
    "CODE_TYPE": "5190",
    "TRADE_SESSION": "0930-1130,1300-1500"
},
{
    "CODE_TYPE": "51a0",
    "TRADE_SESSION": "0900-1330"
},
{
    "CODE_TYPE": "51b0",
    "TRADE_SESSION": "0900-1230,1430-1700"
},
{
    "CODE_TYPE": "5210",
    "TRADE_SESSION": "0900-0300"
},
{
    "CODE_TYPE": "5220",
    "TRADE_SESSION": "0900-0300"
},
{
    "CODE_TYPE": "5230",
    "TRADE_SESSION": "0900-0300"
},
{
    "CODE_TYPE": "5240",
    "TRADE_SESSION": "0900-0300"
},
{
    "CODE_TYPE": "5250",
    "TRADE_SESSION": "0900-0300"
},
{
    "CODE_TYPE": "5260",
    "TRADE_SESSION": "0900-0300"
},
{
    "CODE_TYPE": "5270",
    "TRADE_SESSION": "0900-0300"
},
{
    "CODE_TYPE": "5400",
    "TRADE_SESSION": "0600-0515"
},
{
    "CODE_TYPE": "5500",
    "TRADE_SESSION": "0600-0515"
},
{
    "CODE_TYPE": "5601",
    "TRADE_SESSION": "0600-0400"
},
{
    "CODE_TYPE": "5602",
    "TRADE_SESSION": "0600-0400"
},
{
    "CODE_TYPE": "5608",
    "TRADE_SESSION": "0600-0400"
},
{
    "CODE_TYPE": "560a",
    "TRADE_SESSION": "0600-0400"
},
{
    "CODE_TYPE": "560b",
    "TRADE_SESSION": "0600-0400"
},
{
    "CODE_TYPE": "560c",
    "TRADE_SESSION": "0600-0400"
},
{
    "CODE_TYPE": "560f",
    "TRADE_SESSION": "0600-0400"
},
{
    "CODE_TYPE": "5700",
    "TRADE_SESSION": "0700-0615"
},
{
    "CODE_TYPE": "5800",
    "TRADE_SESSION": "2200-0315"
},
{
    "CODE_TYPE": "5900",
    "TRADE_SESSION": "2000-0230,0900-1130,1330-1530"
},
{
    "CODE_TYPE": "5a00",
    "TRADE_SESSION": "0600-0400"
},
{
    "CODE_TYPE": "5b00",
    "TRADE_SESSION": "0600-0400"
},
{
    "CODE_TYPE": "5c00",
    "TRADE_SESSION": "0700-0600"
},
{
    "CODE_TYPE": "8100",
    "TRADE_SESSION": "0600-0600"
},
{
    "CODE_TYPE": "8200",
    "TRADE_SESSION": "0600-0600"
},
{
    "CODE_TYPE": "9999",
    "TRADE_SESSION": "0000-0000"
}
];


window.alert = function (msg) {
    var html = '<div class="alert">'+msg+'</div>';
    var el = $(html).appendTo('body');
    setTimeout(function () {
        el.remove();
    }, 3000);
}


//涨跌幅计算,四舍五入返回2位小数的百分值
function changeRate(closeprice, pRec) {
    if (pRec < 0.0001) {
        return 0.00;
    } else {
        return ((closeprice - pRec) * 100 / pRec).toFixed(2);
    }

}

//获取小数点位数
function getDecimal(decimal) {
    var result = 2;
    if (decimal == 1) {
        result = 0;
    } else if (decimal == 1000) {
        result = 3;
    } else if (decimal == 10000) {
        result = 4;
    }
    return result;
}

//涨跌点数计算
function difference(closeprice, pRec, decimal) {
    var result = parseFloat(closeprice - pRec).toFixed(decimal);
    if (result > 0 || result < 0) {
        return result;
    } else {
        return 0;
    }
}

//传入商品code_type  得到交易时间段
function getTradeSession(codeType) {
    var result = "";
    for (i = 0; i < codeTypeJson.length; i++) {
        if (codeTypeJson[i].CODE_TYPE == codeType) {
            result = codeTypeJson[i].TRADE_SESSION;
            break;
        }
    }
    return result;
}

//时间戳转换成当地时间,字符串类型。
function timeStamptostr(timestamp, type) {

    var d = new Date(timestamp * 1000); //yyyy-MM-dd hh:mm:ss
    return d.format(type);
}

//时间格式化   alert(d.format("yyyy-MM-dd hh:mm:ss"));
Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1,
        //month
        "d+": this.getDate(),
        //day
        "h+": this.getHours(),
        //hour
        "m+": this.getMinutes(),
        //minute
        "s+": this.getSeconds(),
        //second
        "q+": Math.floor((this.getMonth() + 3) / 3),
        //quarter
        "S": this.getMilliseconds() //millisecond
    }

    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }

    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}

//时间戳转换成当地时间,字符串类型。
function timeStamptostr(timestamp, type) {

    var d = new Date(timestamp * 1000);   //yyyy-MM-dd hh:mm:ss
    return d.format(type);
}

//字符串转化为时间。
function stringtoTime(date1) {
    var dt = new Date(Date.parse(date1.replace(/-/g, "/")));
    return dt;
}

function getLocalTime(nS) {
    return new Date(parseInt(nS) * 1000).toGMTString().replace(/年|月/g, "-").replace(/日/g, " ");
}

function getUrlParams(url) {
    if (!url) {
        url = location.search.substring(1);
    } else {
        url = url.substr(url.indexOf('?') + 1);
    }
    var args = new Object();   // 声明并初始化一个 "类"
    // 获得地址(URL)"?"后面的字符串.

    var query = decodeURI(url);

    var pairs = query.split("&");  // 分割URL(别忘了'&'是用来连接下一个参数)
    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');
        if (pos == -1) continue; // 它在找有等号的 数组[i]
        var argname = pairs[i].substring(0, pos); // 参数名字
        var value = pairs[i].substring(pos + 1);  // 参数值
        // 以键值对的形式存放到"args"对象中
        try {
            args[argname] = decodeURI(value);
        } catch (e) {
            args[argname] = value;
        }
    }
    return args;
}

function ld() {
    $('#loading').show();
}

function lc() {
    $('#loading').hide();
}

function toFixed(num,count) {
    var tmp = parseFloat(num).toFixed(count);
    if (tmp==0) {
        tmp = 0;
    }
    return tmp;
}